import { createSlice, type PayloadAction } from '@reduxjs/toolkit'
// import { produce } from 'immer'
import { PageInfoType } from './types'
import { produce } from 'immer'

const initialState: PageInfoType = {
  title: '',
  desc: '',
  js: '',
  css: '',
}

const pageInfoSlice = createSlice({
  name: 'pageInfo',
  initialState,
  reducers: {
    resetPageInfo: (state: PageInfoType, action: PayloadAction<PageInfoType>) => {
      return {
        ...state,
        ...action.payload,
      }
    },

    changePageTitle: produce((draft: PageInfoType, action: PayloadAction<string>) => {
      draft.title = action.payload
    }),
  },
})

export const pageInfoAction = pageInfoSlice.actions

export default pageInfoSlice.reducer
